function getdistrict(obj,obj2,proid,disid)
{

      var str="<option value=\"0\">"+$(obj+' option:eq(0)').text()+"</option>";
      var str2="<option value=\"0\">"+$(obj2+' option:eq(0)').text()+"</option>";  
      var selected="";
      
      if(proid!=0)
      {
      var xmlRequest=   $.get(serviceinfo+'getdistrict', { proid:proid }, function(data) {  
         
          if(data.error.response)
         {
          alertbox(data.error.error);
         
         }else
         {
         $.each(data['data'], function(key, value) {
           
            //alert(index + ': ' + value);
             selected="";
            if(key==disid)
            {
            selected=' selected="selected" ';
            }
            
             str+="<option "+selected+" value="+key+">"+value+"</option>"; 

            
         
         });
         
         $(obj).html(str);
         $(obj2).html(str2);
         
         
         
         
         }
      
      });
      
      return xmlRequest;
      }else
      {
      $(obj).html(str);
      $(obj2).html(str2);
      }

}

function gettumbon(obj,disid,tumid)
{

      var selected="";
      var strdata="<option value=\"0\">"+$(obj+' option:eq(0)').text()+"</option>"; 
      if(disid!=0)
      {
      $.get(serviceinfo+'gettumbon', { disid:disid }, function(data) {  
         
          if(data.error.response)
         {
          alertbox(data.error.error);
         
         }else
         {
         $.each(data['data'], function(key, value) {
           
            //alert(index + ': ' + value);
             selected="";
            if(key==tumid)
            {
            selected=' selected="selected" ';
            }
            
             strdata+="<option "+selected+" value="+key+">"+value+"</option>"; 

            
         
         });
         
        // console.log(obj);
         $(obj).html(strdata);
         
         
         
         
         }
      
      });
      }else
      {
      $(obj).html(str);
      }

}

function getprovince(obj,proid)
{

      var str="<option value=\"0\">"+$(obj+' option:eq(0)').text()+"</option>";
    //  var str2="<option value=\"0\">"+$(obj2+' option:eq(0)').text()+"</option>";  
      var selected="";
      
    
      var xmlRequest=   $.get(serviceinfo+'getprovince',{noswap:1}, function(data) {  
         
          if(data.error.response)
         {
          alertbox(data.error.error);
         
         }else
         {
         $.each(data['data'], function(key, value) {
           
            //alert(index + ': ' + value);
             selected="";
            if(proid)
            {
            if(key==proid)
            {
            selected=' selected="selected" ';
            }
            }
            
             str+="<option "+selected+" value="+key+">"+value+"</option>"; 

            
         
         });
         
         $(obj).html(str);
       //  $(obj2).html(str2);
         
         
         
         
         }
      
      });
      
      return xmlRequest;
     

}


function getcountry(obj,countryid)
{

      var str="<option value=\"0\">"+$(obj+' option:eq(0)').text()+"</option>";
    //  var str2="<option value=\"0\">"+$(obj2+' option:eq(0)').text()+"</option>";  
      var selected="";
      
    
      var xmlRequest=   $.get(serviceinfo+'getcountry',{noswap:1}, function(data) {  
         
          if(data.error.response)
         {
          alertbox(data.error.error);
         
         }else
         {
         $.each(data['data'], function(key, value) {
           
            //alert(index + ': ' + value);
             selected="";
            if(key==countryid)
            {
            selected=' selected="selected" ';
            }
            
             str+="<option "+selected+" value="+key+">"+value+"</option>"; 

            
         
         });
         
         $(obj).html(str);
       //  $(obj2).html(str2);
         
         
         
         
         }
      
      });
      
      return xmlRequest;
   

}

function getcoverdata(rownow,noopen)
{
  
  if($('#imgdata-'+rownow).length==0) 
   {
   var rowgnow=1;
var code = '<div class="ovlPopGen wrpPopCoverVdo" id="imgdata-'+rownow+'">\n';
code += '<div class="popGen posPop image1">\n';
code += '<div class="topGen clBd2 bdBtm">\n';
code += '<div class="wrpTtlGen">\n';
code += '<h1 class="ttlGen clTxt2 fs05">Video Cover</h1>\n';
code += '</div>\n';
code += '<div class="btnIco closeGen" onclick="$(\'#imgdata-'+rownow+'\').fadeOut()">\n';
code += '<span class="ico icoCloseGen"></span>\n';
code += '</div>\n';
code += '<div class="topBgGen clBg3"></div>\n';
code += '</div>\n';
code += '<div class="bodyGen clBg3">\n';
code += '<div class="bodyOutGen">\n';
code += '<div class="bodyInGen">\n';
code += '<p class="rcmCoverVdo fs02">recommended size : 600px X 600px</p>\n';
code += '<div class="wrpFrmGen">\n';
code += '<div class="wrpInTnAddInfoLd">\n';
code += '<div class="tnAddInfoLd clBd2 clBg4 bdFull plgAreaThumbnail"></div>\n';
code += '<div class="addTnTl clBd2 bdBtm">\n';
code += '<div title="Browse" class="btnIco addImgTl clBd3 bdBtm uploadbutton">\n';
code += '<span class="ico icoAddImgTl"></span>\n';
code += '<div class="wrpUlFile">\n';
code += '</div>\n';
code += '</div>\n';
code += '<div title="Cloud" class="btnIco addCldTl clBd3 bdBtm cloudbutton">\n';
code += '<span class="ico icoAddCldTl"></span>\n';
code += '</div>\n';
code += '<div title="Link" class="btnIco addLnkTl clBd3 bdBtm linkbutton">\n';
code += '<span class="ico icoAddLnkTl"></span>\n';
code += '</div>\n';
code += '<div title="Remove" class="btnIco btnRmvTl deletebutton">\n';
code += '<span class="ico icoRmvTl"></span>\n';
code += '</div>\n';
code += '</div>\n';
code += '</div>\n';
code += '<div class="wrpBtnGen">\n';
code += '<button type="button" onclick="$(\'#imgdata-'+rownow+'\').fadeOut()" class="btnGen clTxtW btnOk cutTxt clBgBt1 fs04">OK</button>\n';
code += '</div>\n';
code += '</div>\n';
code += '</div>\n';
code += '</div>\n';
code += '</div>\n';
code += '</div>\n';
code += '</div>';

    $('#addpopimg').append(code);  
 
    $('#imgdata-'+rownow+' .uploadbutton').iuploader({
         'link':serviceinfo+'iupload',
         'accept':'image/*',
         'group':rowgnow,

         'type':['jpg', 'jpeg', 'png', 'gif'],
         'onUploadFinish':function(filename,filelink,setting){
         
         
         
         
         getpopupboxresize(600,600,filelink,setting['originalwidth'],setting['originalheight'],
         
         function(filename2,filelink2,width2,height2,imgmid2){
         var rowgnow2=setting['group'];        
         //console.log('#imgdata-'+rownow+' .image'+rowgnow2+' .plgAreaThumbnail');
         $('#imgdata-'+rownow+' .image'+rowgnow2+' .plgAreaThumbnail').html('<a target="_blank" href="'+filelink+'?t='+Math.floor((Math.random()*100000)+1)+'"><img height="150" width="150" src="'+filelink2+'?t='+Math.floor((Math.random()*100000)+1)+'"></a>');
         $('#imgdata-'+rownow+' .image'+rowgnow2+' input[name="filelink[]"]').val(filelink);
         $('#imgdata-'+rownow+' .image'+rowgnow2+' input[name="filelinkcrop[]"]').val(filelink2);                 
         $('#imgdata-'+rownow+' .image'+rowgnow2+' input[name="fileold[]"]').val(setting.fileold);      
         $("#width-"+setting.id).val(setting.originalwidth);
         $("#height-"+setting.id).val(setting.originalheight);      
         $("#imgmid-"+setting.id).val(setting.imgmid);       
         $("#simgmid-"+setting.id).val(imgmid2);               
         $("#widthcrop-"+setting.id).val(width2);
         $("#heightcrop-"+setting.id).val(height2);    
         
          closepopup();  
         }
         ,setting['imgmid']
         
         );
         //alert(filename);
         }
   });
  
   $('#imgdata-'+rownow+' .cloudbutton').click(function() {
          //console.log("testdata");
          //var rowgnow3=rowgnow;
          var rowgnow3=1;
        //alert("Handler for .click() called.");
          getpopupcloud(
          function(filename2,filelink2,width2,height2,imgmid2,index2){ 

        $('#imgdata-'+rownow+' .image'+rowgnow3+' .plgAreaThumbnail').html('<a target="_blank" href="'+$('#imgdata-'+rownow+' .image'+rowgnow3+' input[name="filelink[]"]').val()+'?t='+Math.floor((Math.random()*100000)+1)+'"><img height="150" width="150" src="'+filelink2+'?t='+Math.floor((Math.random()*100000)+1)+'"></a>');
         $('#imgdata-'+rownow+' .image'+rowgnow3+' input[name="simgmid[]"]').val(imgmid2);
         $('#imgdata-'+rownow+' .image'+rowgnow3+' input[name="filelinkcrop[]"]').val(filelink2);                                    
         $('#imgdata-'+rownow+' .image'+rowgnow3+' input[name="widthcrop[]"]').val(width2);         
         $('#imgdata-'+rownow+' .image'+rowgnow3+' input[name="heightcrop[]"]').val(height2);

        closepopup();  

          
          },
          
          
          function(filename,filelink,width,height,imgmid,indexnow){
            
            $('#imgdata-'+rownow+' .image'+rowgnow3+' input[name="filelink[]"]').val(filelink);
            $('#imgdata-'+rownow+' .image'+rowgnow3+' input[name="imgmid[]"]').val(imgmid);           
            $('#imgdata-'+rownow+' .image'+rowgnow3+' input[name="width[]"]').val(width);
            $('#imgdata-'+rownow+' .image'+rowgnow3+' input[name="height[]"]').val(height);
            

          
          }
          ,
          rowgnow
          ,600
          ,600
          
          );

   });
   
   $('#imgdata-'+rownow+' .deletebutton').click(function() {
   
   var rowgnow3=1;
   

   $('#imgdata-'+rownow+' .image'+rowgnow3+' .plgAreaThumbnail a').remove();
   
   $('#imgdata-'+rownow+' .image'+rowgnow3+' input[name="filelink[]"]').val('');
   $('#imgdata-'+rownow+' .image'+rowgnow3+' input[name="imgmid[]"]').val('');           
   $('#imgdata-'+rownow+' .image'+rowgnow3+' input[name="width[]"]').val('');
   $('#imgdata-'+rownow+' .image'+rowgnow3+' input[name="height[]"]').val('');
   
   
   
     $('#imgdata-'+rownow+' .image'+rowgnow3+' input[name="simgmid[]"]').val('');
     $('#imgdata-'+rownow+' .image'+rowgnow3+' input[name="filelinkcrop[]"]').val('');                                    
     $('#imgdata-'+rownow+' .image'+rowgnow3+' input[name="widthcrop[]"]').val('');         
     $('#imgdata-'+rownow+' .image'+rowgnow3+' input[name="heightcrop[]"]').val('');
   
   });
   
   $('#imgdata-'+rownow+' .linkbutton').click(function() {
   var rowgnow3=1;
   //console.log("test");
   
   getpopuplink(
          function(filename2,filelink2,width2,height2,imgmid2,index2){ 
          
          
         $('#imgdata-'+rownow+' .image'+rowgnow3+' .plgAreaThumbnail').html('<a target="_blank" href="'+$('#imgdata-'+rownow+' .image'+rowgnow3+' input[name="filelink[]"]').val()+'?t='+Math.floor((Math.random()*100000)+1)+'"><img height="150" width="150" src="'+filelink2+'?t='+Math.floor((Math.random()*100000)+1)+'"></a>');
         
         $('#imgdata-'+rownow+' .image'+rowgnow3+' input[name="simgmid[]"]').val(imgmid2);
         $('#imgdata-'+rownow+' .image'+rowgnow3+' input[name="filelinkcrop[]"]').val(filelink2);                                    
         $('#imgdata-'+rownow+' .image'+rowgnow3+' input[name="widthcrop[]"]').val(width2);         
         $('#imgdata-'+rownow+' .image'+rowgnow3+' input[name="heightcrop[]"]').val(height2);
        // $.colorbox.close("User added succesfully"); 
        closepopup();  
          
          },
          function(filename,filelink,width,height,imgmid,indexnow){
            

            $('#imgdata-'+rownow+' .image'+rowgnow3+' input[name="filelink[]"]').val(filelink);
            $('#imgdata-'+rownow+' .image'+rowgnow3+' input[name="imgmid[]"]').val(imgmid);           
            $('#imgdata-'+rownow+' .image'+rowgnow3+' input[name="width[]"]').val(width);
            $('#imgdata-'+rownow+' .image'+rowgnow3+' input[name="height[]"]').val(height);
            

          
          }
          ,
          rowgnow
          ,600
          ,600
   );
   
   });
   
 
 
 
 
   }
   
   
 //  'wrpPopCoverVdo';
 if(noopen)
 {
 
 }else
 {
 $('#imgdata-'+rownow).fadeIn();
 
 }
 
 

}

function is_object (mixed_var) {
  // http://kevin.vanzonneveld.net
  // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
  // +   improved by: Legaev Andrey
  // +   improved by: Michael White (http://getsprink.com)
  // *     example 1: is_object('23');
  // *     returns 1: false
  // *     example 2: is_object({foo: 'bar'});
  // *     returns 2: true
  // *     example 3: is_object(null);
  // *     returns 3: false
  if (Object.prototype.toString.call(mixed_var) === '[object Array]') {
    return false;
  }
  return mixed_var !== null && typeof mixed_var === 'object';
}


function bookingnow()
{
if($( '#main-middle .bookingcontent input[name="checkindate"]').val()&&$( '#main-middle .bookingcontent input[name="checkoutdate"]').val())
{
var day=getDaysBetweenDates($( '#main-middle .bookingcontent input[name="checkindate"]').val(), $( '#main-middle .bookingcontent input[name="checkoutdate"]').val());

var n0=$( '#main-middle .bookingcontent input[name="checkindate"]').val().split("/"); 

var newWindow = window.open('', '_blank');
loaddata();
var productxhr=$.get(serviceinfo+'genservicerefcode', function(data) {  

loadclosedata();
if(data.error.response)
{
if(data.error.error[0].code==5)
{
$('.ovlPopLd').hide();
$('.wrpPopLI').fadeIn();

//console.log('test');
}else
{
//alertbox(data.error.error);

alertbox(data.error.error);
}

}
else
{
var linktobooking='http://www.dnp.go.th/parkreserve/reservation_t1c.asp?actiontype=search&lg=1&npid=113&refcode='+data.data.refcode+'&s_day='+n0[0]+'&s_month='+n0[1]+'&s_year='+n0[2]+'&Night='+day+'&preid=1&otherpre=Mr.&cusname='+data.data.user.userdata.firstname+'&cuslname='+data.data.user.userdata.lastname+'&cusaddr=12&cusprovince='+data.data.user.userdata.state+'&cuspostcode='+data.data.user.userdata.code+'&custel='+data.data.user.userdata.phone+'&cusfax='+data.data.user.userdata.fax+'&cusemail='+data.data.user.userdata.email+'&cuswebsite='+data.data.user.userdata.website+'';

newWindow.location = linktobooking;
}

});


}



}
var stateclick=1;
function setcookiestate()
{
var getstateclick=getCookie('stateclick');

if(getstateclick==1||getstateclick==null)
{
stateclick=2;

}else
{
stateclick=1;

}


setCookie('stateclick', stateclick,  0, 0, 0, 0) ;

}

function setCookie(name, value,    expires, path, domain, secure) {
    document.cookie= name + "="    + escape(value)    +
    ((expires) ? ";    expires=" + expires.toGMTString() : "")    +
    ((path)    ? "; path=" + path : "") +
    ((domain) ? "; domain="    + domain : "") +
    ((secure) ? "; secure" : "");
}

function getCookie(name) {
    var    dc = document.cookie;
    var    prefix = name +    "=";
    var    begin =    dc.indexOf("; "    + prefix);
    if (begin == -1) {
    begin =    dc.indexOf(prefix);
    if (begin != 0)    return null;
    } else {
    begin += 2;
    }
    var    end = document.cookie.indexOf(";", begin);
    if (end == -1) {
    end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length,    end));
}

function deleteCookie(name, path, domain) {
    if (getCookie(name)) {
    document.cookie    = name + "=" +
        ((path) ? "; path="    + path : "") +
        ((domain) ?    "; domain=" + domain : "") +
        "; expires=Thu, 01-Jan-70 00:00:01 GMT";
    }
}

function alertbox(msg)
{


        if(is_object(msg)||msg.length)
        {
 var code = '<div class="wrpMiniPop clBgBt1" onclick="$(\'.ovlPopGen.wrpAddAlert\').fadeOut()">\n';
code += '<div class="miniPop">\n';
code += '<div class="signMiniPop">\n';



//code += '<div class="bgSignMiniPop clBgSp1">\n';
//code += '<span class="ico icoCrt icoCrtMiniPop"></span>\n';
//code += '</div>\n';

code +='<div class="bgSignMiniPop clErrBg">';
code +='<span class="ico icoWrngMiniPop"></span>';
code +='</div>';

code += '</div>\n';       
        $.each(msg, function(key, value) {
        if(value.code==1)
        {
        
        redirectto(serviceinfo+'logout?linkto='+checknowurl+'&nojson=1');
        return false;
        }
        if(value.msg)
        {
        //alertboxui(value.msg);
        
        
        
        code += '<span class="txtMiniPop fs07 clTxtW">'+value.msg+'</span><br>\n';
        
        }
        
        });
code += '</div>\n';
code += '</div>';

$(".ovlPopGen.wrpAddAlert").html(code);
$(".ovlPopGen.wrpAddAlert").fadeIn();

var t=setTimeout(function(){$(".ovlPopGen.wrpAddAlert").fadeOut()},3000);


//setTimeout($(".ovlPopGen.wrpAddAlert").fadeOut(), 3000);
        
        }else
        {
        
        alert(msg);
        }
        
}

function alertwrongbox(msg)
{


        if(is_object(msg)||msg.length)
        {
 var code = '<div class="wrpMiniPop clBgBt1" onclick="$(\'.ovlPopGen.wrpAddAlert\').fadeOut()">\n';
code += '<div class="miniPop">\n';
code += '<div class="signMiniPop">\n';
//code += '<div class="bgSignMiniPop clBgSp1">\n';
//code += '<span class="ico icoCrt icoCrtMiniPop"></span>\n';
//code += '</div>\n';

code +='<div class="bgSignMiniPop clErrBg">';
code +='<span class="ico icoWrngMiniPop"></span>';
code +='</div>';

code += '</div>\n';       
        $.each(msg, function(key, value) {
        
        if(value.msg)
        {
        //alertboxui(value.msg);
        
        
        
        code += '<span class="txtMiniPop fs07 clTxtW">'+value.msg+'</span><br>\n';
        
        }
        
        });
code += '</div>\n';
code += '</div>';

$(".ovlPopGen.wrpAddAlert").html(code);
$(".ovlPopGen.wrpAddAlert").fadeIn();

var t=setTimeout(function(){$(".ovlPopGen.wrpAddAlert").fadeOut()},3000);


//setTimeout($(".ovlPopGen.wrpAddAlert").fadeOut(), 3000);
        
        }else
        {
        
        alert(msg);
        }
        
}

function alertwrongboxmsgonly(msg)
{


        if(msg)
        {
 var code = '<div class="wrpMiniPop clBgBt1" onclick="$(\'.ovlPopGen.wrpAddAlert\').fadeOut()">\n';
code += '<div class="miniPop">\n';
code += '<div class="signMiniPop">\n';
//code += '<div class="bgSignMiniPop clBgSp1">\n';
//code += '<span class="ico icoCrt icoCrtMiniPop"></span>\n';
//code += '</div>\n';

code +='<div class="bgSignMiniPop clErrBg">';
code +='<span class="ico icoWrngMiniPop"></span>';
code +='</div>';

code += '</div>\n';       
     
        //alertboxui(value.msg);
        
        
        
        code += '<span class="txtMiniPop fs07 clTxtW">'+msg+'</span><br>\n';
        

code += '</div>\n';
code += '</div>';

$(".ovlPopGen.wrpAddAlert").html(code);
$(".ovlPopGen.wrpAddAlert").fadeIn();

var t=setTimeout(function(){$(".ovlPopGen.wrpAddAlert").fadeOut()},3000);


//setTimeout($(".ovlPopGen.wrpAddAlert").fadeOut(), 3000);
        
        }else
        {
        
        alert(msg);
        }
        
}


function alertrightboxmsgonly(msg)
{


        if(msg)
        {
 var code = '<div class="wrpMiniPop clBgBt1" onclick="$(\'.ovlPopGen.wrpAddAlert\').fadeOut()">\n';
code += '<div class="miniPop">\n';
code += '<div class="signMiniPop">\n';
code += '<div class="bgSignMiniPop clBgSp1">\n';
code += '<span class="ico icoCrt icoCrtMiniPop"></span>\n';
code += '</div>\n';
code += '</div>\n';       

        //alertboxui(value.msg);
        
        
        
        code += '<span class="txtMiniPop fs07 clTxtW">'+msg+'</span><br>\n';
        

code += '</div>\n';
code += '</div>';

$(".ovlPopGen.wrpAddAlert").html(code);
$(".ovlPopGen.wrpAddAlert").fadeIn();

var t=setTimeout(function(){$(".ovlPopGen.wrpAddAlert").fadeOut()},3000);


//setTimeout($(".ovlPopGen.wrpAddAlert").fadeOut(), 3000);
        
        }else
        {
        
        alert(msg);
        }
        
}


function statdatalink(link,bannerid)
{

$.post(serviceinfo+"statdatabanner",{bannerid:bannerid},
function(data){

location.href=link;

});


}

function alertboxtext(msg,setdata)
{
        setdata.html('')
        ; 
        var str;  
        var nowrow=1;  
        if(msg.length)
        {
        $.each(msg, function(key, value) {
        if(value.msg)
        {
         str='<div class="wrnLS wls'+nowrow+'" id="errornow-'+nowrow+'"><div class="errLS clErrBg" onclick="$(\'#errornow-'+nowrow+'\').remove()"><span  class="ico icoErr"></span></div><span class="spnErrLS clErrTxt fs02" id="validateerror-login-msg" >'+value.msg+'</span></div>';
         
         nowrow++;
        
        setdata.append(str);
        }
        });
        
        }
        else
        {
        setdata.append(msg);
        }
        setdata.show();
        
}





function loaddata()
{
$.blockUI({ message: '<h1><img src="'+baseinfo+'/css/theme1/img/imgload.gif" /></h1>' }); 

}
function loaddatabymsg(msgdata)
{
$.blockUI({ message: '<div class="warnningdiv">'+msgdata+'</div>' }); 

}
function alertboxui(msgdata)
{
//$.blockUI({ message: '<div id="questionworld" style=" width: 256px;"> <p>'+msgdata+'</p> </div>', css: { width: '275px' } });     
$.blockUI({ message: '<h1><img src="'+baseinfo+'/css/theme1/img/imgload.gif" /></h1>' }); 
setTimeout($.unblockUI, 2000); 


}


function boxmsgdata(msgdata)
{
var code = '<div class="wrpMiniPop clBgBt1" onclick="$(\'.ovlPopGen.wrpAddAlert\').fadeOut()">\n';
code += '<div class="miniPop">\n';
code += '<div class="signMiniPop">\n';
code += '<div class="bgSignMiniPop clBgSp1">\n';
code += '<span class="ico icoCrt icoCrtMiniPop"></span>\n';
code += '</div>\n';
code += '</div>\n';

code += '<span class="txtMiniPop fs07 clTxtW">'+msgdata+'</span>\n';

code += '</div>\n';
code += '</div>';

$(".ovlPopGen.wrpAddAlert").html(code);
$(".ovlPopGen.wrpAddAlert").fadeIn();

setTimeout(closeboxmsgdata, 3000); 


}
function closeboxmsgdata()
{
$('.ovlPopGen.wrpAddAlert').fadeOut();
}
function boxconfirmmsgdata(msgdata,functioncallback,parameterset)
{
var code = '<div class="wrpMiniPop clBgBt1">\n';
code += '<div class="miniPop">\n';
code += '<div class="signMiniPop">\n';
code += '<div class="bgSignMiniPop clWarnBg">\n';
code += '<span class="ico icoWrnMiniPop"></span>\n';
code += '</div>\n';
code += '</div>\n';
code += '<span class="txtMiniPop fs07 clTxtW">'+msgdata+'</span>\n';
code += '<div class="wrpBtnMiniPop">\n';
code += '<span class="btnIco btnMiniPop clTxtW fs03" onclick="'+functioncallback+'('+parameterset+');$(\'.ovlPopGen.wrpAddAlert\').fadeOut()">Yes</span>\n';
code += '<span class="btnIco btnMiniPop clTxtW fs03" onclick="$(\'.ovlPopGen.wrpAddAlert\').fadeOut()">No</span>\n';
code += '</div>\n';
code += '</div>\n';
code += '</div>';
$(".ovlPopGen.wrpAddAlert").html(code);
$(".ovlPopGen.wrpAddAlert").fadeIn();


}



function initmapdata()
{
    
 $.each($('#main-middle input[name="mapiddatanow[]"]'), function(index ) {
    
    if($(this).val())
    {
   //  console.log($(this).val());
     var latset=$('#main-middle input[name="latdatanow[]"]:eq('+index+')').val();
     var lngset=$('#main-middle input[name="lngdatanow[]"]:eq('+index+')').val();
     var latLng={lat:latset,lng:lngset};
    // console.log(latLng);
              $('#mapid'+$(this).val()).gmap3('destroy');
              $('#mapid'+$(this).val()).gmap3({
                  marker:{ 
                    latLng:latLng,
                    options:{
                        draggable: false
                    }
                    },
                      map:{
                        options:{
                          zoom: 15,
                          center :latLng
                        }
                      }
                });
    
    
    }
 
 });

}
function initvideodata()
{
 $.each($('#main-middle input[name="urlvdo[]"]'), function(index ) {
  
  var ext = $(this).val().split('.').pop().toLowerCase();
  var idvdoset=$('#main-middle input[name="vdoidvdo[]"]:eq('+index+')').val();
      if(ext=="mp4") 
    {
    var urldata='<video width="100%" height="360" controls><source src="'+$(this).val()+'" type="video/mp4"></video>';

    }else
    {
    var urldata='<iframe width="100%" height="360" src="'+$(this).val()+'"> </iframe>';
    }
  
  
  
 
 
 var t=setTimeout(function(){$("#vdodatasetnow-"+idvdoset).html(urldata)},3000)
 
 });

}

function initvideomp4data()
{
$('.wrpVdoLdcheckrow div div').remove();


$.each($('.wrpVdoLdcheckrow video'), function(index ) {
var myVideo=document.getElementById($(this).attr('id'));
myVideo.pause();

});

 $.each($('#main-middle .wrpVdoLdcheckrow video'), function(index ) {




   
   
   MediaElement($(this).attr('id'), {success: function(me) {
   

    
    $('#main-middle .wrpVdoLdcheckrow div div').click(function() {
          if (me.paused)
            me.play();
        else
            me.pause();
        });
  //me.play();

}});



 });
 


}


function popupactivites(title,description)
{

var code = '<div class="popGen posPop">\n';
code += '<div class="topGen clBd2 bdBtm">\n';
code += '<div class="wrpTtlGen">\n';
code += '<h1 class="ttlGen clTxt2 fs05">Activity</h1>\n';
code += '</div>\n';
code += '<div class="btnIco closeGen" onclick="closepopupactivity()">\n';
code += '<span class="ico icoCloseGen"></span>\n';
code += '</div>\n';
code += '<div class="topBgGen clBg3"></div>\n';
code += '</div>\n';
code += '<div class="bodyGen clBg3">\n';
code += '<div class="bodyOutGen">\n';
code += '<div class="bodyInGen">\n';
code += '<p class="desAddGen clTxt2 boldGen fs03">'+title+'</p>\n';
code += '<div class="wrpFrmGen">\n';
code += '<textarea readonly="" class="frmShw frmGen clBg4 clTxt3 fs03">'+description+'</textarea>\n';
code += '<div class="wrpBtnGen">\n';
code += '<button type="button" class="btnGen btnOk clTxtW cutTxt clBgSp2 fs04" onclick="closepopupactivity()">OK</button>\n';
code += '</div>\n';
code += '</div>\n';
code += '</div>\n';
code += '</div>\n';
code += '</div>\n';
code += '</div>';
$(".ovlPopGen.wrpAddAct").html(code);
$(".ovlPopGen.wrpAddAct").fadeIn();


}

function initmapdataroute()
{

var genmappoint={};
var genpoint={};  
var genpointarr=new Array();
var rowgenmap=0;
$.each($('#main-middle .pointTripData'), function(index ) {

if($(this).find('input[name="latset[]"]').val()!='0.000000000000000'&&$(this).find('input[name="latset[]"]').val())
{

genmappoint[rowgenmap]=new google.maps.LatLng($(this).find('input[name="latset[]"]').val(),$(this).find('input[name="lngset[]"]').val())
;
genpointarr[rowgenmap]={latLng:[$(this).find('input[name="latset[]"]').val(), $(this).find('input[name="lngset[]"]').val()],options:{icon: iconBase +pointData[rowgenmap]+'_maps.png'}};

genpoint[rowgenmap]={point:$(this).find('.clTxtW.fs02').html()};

rowgenmap++;

}



});


 //console.log(Object.keys(genmappoint).length);   
 
if(Object.keys(genmappoint).length>1)
{

  if(Object.keys(genmappoint).length>2)
  {
   var waypts=[];
   var rowwaypts=0;
  $.each(genmappoint, function(index, value) {
       
          if(rowwaypts!=0&&rowwaypts!=(Object.keys(genmappoint).length-1))
          {
          waypts.push(
          {
                location:new google.maps.LatLng(value.lat(),value.lng()),
                stopover:true
          }
          );
          }
          
          
          rowwaypts++;
                     
        //alert(index + ': ' + value);
        
        
        });
        
    var objset= {
        origin:genmappoint[0],
        destination:genmappoint[Object.keys(genmappoint).length-1],
        optimizeWaypoints: true,  
        avoidTolls:true,
        waypoints:waypts,
        avoidHighways:true,
        provideRouteAlternatives:true,
        travelMode: google.maps.DirectionsTravelMode.DRIVING
    };      
  
  
  }else
  {
  var objset= {
        origin:genmappoint[0],
        destination:genmappoint[Object.keys(genmappoint).length-1],
        optimizeWaypoints: true,  
        avoidTolls:true,
        avoidHighways:true,
        provideRouteAlternatives:true,
        travelMode: google.maps.DirectionsTravelMode.DRIVING
    };
  }
//console.log(objset);
 $("#main-middle .mapdataroute").gmap3('destroy');
$("#main-middle .mapdataroute").gmap3({

  
   
  getroute:{
    options:objset,
    callback: function(results){

      
     // console.log(results);   
     

      $(this).gmap3({
        map:{
          options:{
            zoom: 17, 
            center: genmappoint[0]
          }
        },
        directionsrenderer:{
          options:{
            directions:results
          }
        }
      });
    
    
    
    }
  }
});
}
else if(Object.keys(genmappoint).length==1)
{
$("#main-middle .mapdataroute").gmap3('destroy');
$("#main-middle .mapdataroute").gmap3({
      map:{
          options:{
            zoom: 17, 
            center: genmappoint[0]
          }
        },
         marker:{
    values:genpointarr,
    options:{
      draggable: false
    }
      
      }
      
      });

}



}

function initmapdataroute2()
{

opentourdata(1,1);
}

function loadclosedata()
{

$.unblockUI();

}

function linkto(link)
{
var newWindow = window.open('', '_blank');
newWindow.location = link;


}
function redirectto(link)
{
location.href=link;

}
var firstbroadcasting=1;
function saveboradcastingdata()
{

if($('#txtbroadcast').val())
{

loaddata();
$.post(serviceinfo+"sendboardcasting",{msg:$('#txtbroadcast').val()},
function(data){
loadclosedata();
if(data.error.response)
{

boxmsgdata(data.error.error);

//alertboxtext(data.error.error,$("#validateerror-login"));

}else
{
boxmsgdata('Success');
$('#txtbroadcast').val('');
//location.href=baseinfo;


}


});


}


}
function openbroadcasting()
{
$('.wrpPopCrteBc .ttlGen').html('Create Broadcast');
$('.wrpPopCrteBc #txtbroadcast').val('');
$('.wrpPopCrteBc .desAddGen').html('Send the message or url link to all followers person.');
$('.wrpPopCrteBc .btnSend').attr('onclick','saveboradcastingdata()');
$('.wrpPopCrteBc').fadeIn();



if(firstbroadcasting)
{
firstbroadcasting=0;

$('#txtbroadcast').keyup(function() {



var datatext=$(this).val().length;

$('.wrpPopCrteBc .countCha').html(128-datatext);
  
});
}


}
function savenotifydata()
{


if($('#txtbroadcast').val())
{

loaddata();
$.post(serviceinfo+"sendnotify",{msg:$('#txtbroadcast').val()},
function(data){
loadclosedata();
if(data.error.response)
{

boxmsgdata(data.error.error);

//alertboxtext(data.error.error,$("#validateerror-login"));

}else
{
boxmsgdata('Success');
$('#txtbroadcast').val('');
//location.href=baseinfo;


}


});


}


}
function opennotify()
{
$('.wrpPopCrteBc .ttlGen').html('Create Notification');
$('.wrpPopCrteBc .desAddGen').html(' Notify to all member.');
$('.wrpPopCrteBc #txtbroadcast').val('');
$('.wrpPopCrteBc .btnSend').attr('onclick','savenotifydata()');
$('.wrpPopCrteBc').fadeIn();
if(firstbroadcasting)
{
firstbroadcasting=0;

$('#txtbroadcast').keyup(function() {



var datatext=$(this).val().length;

$('.wrpPopCrteBc .countCha').html(128-datatext);
  
});
}


}
function iResize() {
    document.getElementById('bgIframeid').style.height = document.getElementById('bgIframeid').contentWindow.document.body.offsetHeight + 'px';
}
function openifame(linkifame)
{

$('.wrpOutCtnt.w960 .wrpInCtnt').html('<iframe class="bgIframe" src="'+linkifame+'"></iframe>');


}

function savephonedata()
{
      $('.wrprMiniPop.wrpPopMiniTel').fadeOut();    
   if($('#phoneuser').val()=="")
   {

   boxmsgdata('Please Insert Phone');
   
   }else
   {

   loaddata();
  $.post(serviceinfo+'savesetting', {filter:1,phone:$('#phoneuser').val()}, function(data) {  
   loadclosedata();   
    if(data.error.response)
    {
    alertbox(data.error.error);

    }else
    {
    boxmsgdata('Done');
    savereservedata(productidsetres);
    
    }  
  
  
  })
   }

}

function openreport(type,productid,userid)
{

var code = '<div class="popGen posPop">\n';
code += '<div class="topGen clBd2 bdBtm">\n';
code += '<div class="wrpTtlGen">\n';
code += '<h1 class="ttlGen clTxt2 fs05">Report</h1>\n';
code += '</div>\n';
code += '<div class="btnIco closeGen" onclick="closepopupdata()">\n';
code += '<span class="ico icoCloseGen"></span>\n';
code += '</div>\n';
code += '<div class="topBgGen clBg3"></div>\n';
code += '</div>\n';
code += '<div class="bodyGen clBg3">\n';
code += '<div class="bodyOutGen">\n';
code += '<div class="bodyInGen">\n';
code += '<div class="wrpFrmGen">\n';
code += '<textarea  class="reportTextArea frmTxtArea frmGen clBg4 clTxt3 fs03"></textarea>\n';
code += '<div class="wrpBtnGen">\n';
code += '<button type="button" onclick="savereport('+type+','+productid+','+userid+')" class="btnGen clTxtW btnOk cutTxt clBgBt1 fs04">OK</button>\n';
code += '</div>\n';
code += '</div>\n';
code += '</div>\n';
code += '</div>\n';
code += '</div>\n';
code += '</div>';

$(".ovlPopGen.wrpPopAddPop").html(code);
$(".ovlPopGen.wrpPopAddPop").fadeIn();


}
function closepopupdata()
{
$(".ovlPopGen.wrpPopAddPop").html('');
$(".ovlPopGen.wrpPopAddPop").fadeOut();

}

function deleteproduct(productid,backstate)
{
if(backstate)
{
productid=productid+','+backstate;
}else
{
productid=productid+',0';

}
boxconfirmmsgdata('ต้องการลบ product หรือไม่','deleteproduct2',productid);




}

function deleteproduct2(productid,backstate)
{


loaddata();
$.post(serviceinfo+'deleteproduct', { productid:productid }, function(data) { 
loadclosedata();

if(data.error.response)
{
boxmsgdata(data.error.error);

}else
{
if(backstate)
{
window.history.back();

}else
{
boxmsgdata('Success');
$('#wrpInCell-'+productid).remove();
//console.log($(".wrpCell.mainCell.clearfix .wrpInCell").length);
if($(".wrpCell.mainCell.clearfix .wrpInCell").length==0)
{
var code='<div class="nodata"><span class="cltxt3 fs04">No data, please add content.</span></div>';
  $(".wrpCell.mainCell").html(code);
}
}

}


});


}

function savereport(type,productid,userid)
{
loaddata();
$.post(serviceinfo+"savereport",{report:$('.reportTextArea').val(),type:type,productid:productid,userid:userid},
function(data){
loadclosedata();
boxmsgdata('Success');

$(".ovlPopGen.wrpPopAddPop").html('');
$(".ovlPopGen.wrpPopAddPop").fadeOut();
});


}
function destroyclose()
{

    var slider = $("#gallery-2").data('royalSlider');

    slider.destroy();

}
var diskeyborad=0;
function openmaingallery(idimg)
{




$('#gallery-2').html('');
var rsImg='';
var titledetail='';
var indexdata=0;
$('#main-middle a.galleryimage img').each(function( index ) {
//linkarr[rowdata]=$(this).attr("title");
 titledetail=$($(this).parents().parents().eq(0)).find('.cutTxt').html();
var nrowsize=$(this).attr("alt").split("|"); 
var idimgset=$(this).attr("id").split("-"); 
var idnowimgset=parseInt(idimgset[1],10);
if(idnowimgset==idimg)
{
indexdata=index;

}
//console.log($(this).parents().parents().eq(0).html());

//console.log($($(this).parents().parents().eq(0)).find('.cutTxt').html());

var heightnew=parseInt(nrowsize[1],10);
var widthnew=parseInt(nrowsize[0],10);
var widthsizenew=(72*widthnew)/heightnew;
rsImg='<a class="rsImg" data-rsBigImg="'+$(this).attr("title")+'" href="'+$(this).attr("title")+'" data-rsw="'+nrowsize[0]+'" data-rsh="'+nrowsize[1]+'"><p>'+titledetail+'</p></a>';
$('#gallery-2').append(rsImg);


//rowdata++;
});


 $('.ovlPopGen.wrpPopAddPop2').fadeIn('slow', function() {
// Animation complete
  $('#gallery-2').royalSlider({
        addActiveClass: true,
    arrowsNav: false,
    controlNavigation: 'none',
    autoScaleSlider: true, 
    autoScaleSliderWidth: 960,     
    autoScaleSliderHeight: 400,
    loop: true,
    fadeinLoadedSlide: false,
    globalCaption: true,
    startSlideId:indexdata,
    keyboardNavEnabled: true,
    globalCaptionInside: false,
    imageAlignCenter:  true,
    visibleNearby: {
      enabled: true,
      centerArea: 0.8,
      center: true,
      breakpoint: 320,
      breakpointCenterArea: 0.6,
      navigateByCenterClick: true
    }
  });
  
  
  var slider = $("#gallery-2").data('royalSlider');
 slider.ev.on('rsAfterContentSet', function(e, slideObject) {
diskeyborad=1;
    // fires when every time when slide content is loaded and added to DOM
});
  
slider.ev.on('rsBeforeDestroy', function() {
  diskeyborad=0;
    // triggers before slider in destroyed
});


});




}

function clearproductdata()
{

     pagemain=1;
                fistcheck=0;
                lastcheck=0;
    
    

                pagemain=1;

                enddata=0;
                        
                        cellnum=0;

                        process=0;
                        targetdiv='';
      checkfirstrowdata=0;
    
                $(".wrpCell.mainCell").html('');
    datamain=new Array();
    
        datamain={};
        celldata=new Array();


}

//start 2-09-2556
function setpagination(div,pageallset,rowpage,func,param1,param2,param3)
{

$(div).pagination({
        items: pageallset,
        itemsOnPage: rowpage,
        cssStyle: 'light-theme',
        reverse:1,
        onPageClick: function(pageNumber, event) {
                   
                   
                   
                   
                   eval(func+"("+pageNumber+",'"+param1+"','"+param2+"','"+param3+"')")
       
                    // Callback triggered when a page is clicked
                    // Page number is given as an optional parameter
                }
    });

}
function setpaginationnoreverse(div,pageallset,rowpage,func,param1,param2,param3)
{

$(div).pagination({
        items: pageallset,
        itemsOnPage: rowpage,
        cssStyle: 'light-theme',
        reverse:0,
        onPageClick: function(pageNumber, event) {
                   
                   
                   
                   
                   eval(func+"("+pageNumber+",'"+param1+"','"+param2+"','"+param3+"')")
       
                    // Callback triggered when a page is clicked
                    // Page number is given as an optional parameter
                }
    });

}
function setpaginationdatalink(div,pageallset,nowpage,rowpage,linktopage)
{

$(div).pagination({
        items: pageallset,
        itemsOnPage:rowpage,
        currentPage:nowpage,
        cssStyle: 'light-theme',
        reverse:0,
        onPageClick: function(pageNumber, event) {
                   
                   
                   location.href=linktopage+pageNumber;
                   
                  // eval(func+"("+pageNumber+",'"+param1+"','"+param2+"','"+param3+"')")
       
                    // Callback triggered when a page is clicked
                    // Page number is given as an optional parameter
                }
    });

}
            //end 2-09-2556 



